package zuk.clipvietfun.clipadapter;



import java.util.ArrayList;
import java.util.List;

import com.google.android.youtube.player.internal.p;

import zuk.clipvietfun.getdata.SetList;

import android.content.Context;
import android.os.AsyncTask;

public class LoadClipEnlessAdapterTask extends
		AsyncTask<List<Clip>, Void, List<Clip>> {
	private Context mContext;
	private ClipAdapter mAdapter;

	List<Clip> listresult;
	private boolean mReachedLastPage;

	public LoadClipEnlessAdapterTask(Context context, ClipAdapter mAdapter) {

		setmContext(context);
		this.mAdapter = mAdapter;
		mReachedLastPage = false;

	}

	@Override
	protected List<Clip> doInBackground(List<Clip>... params) {

		listresult = params[0];
		System.out.println(listresult.size());
		if(listresult.size()<20){
			mReachedLastPage = true;
		}
		return listresult;

		
	}

	@Override
	protected void onPostExecute(List<Clip> result) {
		super.onPostExecute(result);
		for (Clip clip : result) {
			mAdapter.add(clip);
			mAdapter.notifyDataSetChanged();
		}
		if (mReachedLastPage){
            mAdapter.notifyNoMoreItems();
        }

	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	public Context getmContext() {
		return mContext;
	}

}
